
import 'dart:convert';

import 'package:wanxiang_app/bean/login_entity.dart';
import 'package:wanxiang_app/utils/sp_util.dart';





class UserUtil {
  static const String SP_SERVICE= "sp_service";
  static const String SP_USER_TOKEN = "sp_user_token";
  static const String SP_USER_ACCOUNT = "sp_user_account";
  static const String SP_USER_PWD = "sp_user_pwd";
  static const String SP_USER = "sp_user";
  static  String USER_INFO = "";
  static const String SP_KEFU = "kefu";
  static const String SP_RECORD = "records_lists";
  static const String FIRST = "isFirst";
  static const String TIP = "isTip";

  static String? saveTip(String token) {
    SpUtil.putString(TIP, token);
  }

  static String getTip() {
    String token = SpUtil.getString(TIP);
    return token;
  }

  static String? saveFirst(String token) {
    SpUtil.putString(FIRST, token);
  }

  static String getFirst() {
    String token = SpUtil.getString(FIRST);
    return token;
  }
  static String? saveService(String token) {
    SpUtil.putString(SP_SERVICE, token);
  }

  static String getService() {
    String token = SpUtil.getString(SP_SERVICE);
    return token;

  }
  static String? saveToken(String token) {
    SpUtil.putString(SP_USER_TOKEN, token);
  }
  static String? saveAccount(String account) {
    SpUtil.putString(SP_USER_ACCOUNT, account);
  }
  static String? saveKefu(String account) {
    SpUtil.putString(SP_KEFU, account);
  }

  static String? saveRecord(String account) {
    SpUtil.putString(SP_RECORD, account);
  }

  static String getRecord() {
    String token = SpUtil.getString(SP_RECORD);
    return token;

  }

  static String getKefu() {
    String token = SpUtil.getString(SP_KEFU);
    return token;
  }

  static String? saveUSER(	LoginData data) {
    SpUtil.putObject(SP_USER, data);
  }
  static String? saveUSER2(	String data) {
    SpUtil.putObject33(SP_USER, data);
  }
  static LoginData? getUSER() {
    Map? token = SpUtil.getObject2(SP_USER);
    print(token);
    if(token!=null){
      LoginData homeEntity = LoginData.fromJson(token as Map<String,dynamic>);
      return homeEntity;
    }else{
      LoginData loginData = LoginData();
      return loginData;
    }

     SpUtil.getString(SP_USER);
  }

  static String getAccount() {
    String token = SpUtil.getString(SP_USER_ACCOUNT);

    return token;
  }
  static String getPwd() {
    String token = SpUtil.getString(SP_USER_PWD);
    return token;
  }
  //获取用户信息
  static String getToken() {
    String token = SpUtil.getString(SP_USER_TOKEN);

    return token;
  }

  //退出登录
  static loginout() {
    USER_INFO = "";
    SpUtil.clear();
    // LoginData loginData = LoginData();
    // loginData.userName='';
    // loginData.idCard='';
    // loginData.id=0;
    // saveUSER(loginData);
  }


  static bool isLogin() {

    return true;
  }
}
